package org.grayrabbit.cms.action.generate;

import java.io.File;
import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.grayrabbit.cms.action.common.SimpleAction;
import org.grayrabbit.cms.constant.ConstantTheme;
import org.grayrabbit.cms.util.FilePathSptUtil;


import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.TemplateException;

public class GenAction extends SimpleAction{
 
	private static final long serialVersionUID = -8284127279476624785L;
	@Resource
	private Configuration config; 
	
	/**系统主题根路径 相对路径
	 * @return
	 */
	public String getSystemThemeRoot(){		 
		return ConstantTheme.THEME;
	} 
	
	public Configuration getConfig() throws IOException, TemplateException {
		String realThemeRootpath =  FilePathSptUtil.THEME_ROOT_PATH+getSystemThemeRoot();
		config.setDirectoryForTemplateLoading(new File(realThemeRootpath));
		config.setObjectWrapper(new DefaultObjectWrapper());
		return config;
	}

	public void setConfig(Configuration config) {
		this.config = config;
	}

	public HttpServletResponse getResponse() {
		 return ServletActionContext.getResponse();  
	}
}
